<%@ page import="com.actimind.actitime.Keys,com.actimind.actitime.reports.*,
                 com.actimind.actitime.util.StringUtils"%>
<%@ page errorPage="/error.jsp" %>
<%@ taglib uri="/WEB-INF/at.tld" prefix="at" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<at:CheckLoggedIn/>

<html>
<head>
    <title><bean:write name="title-prefix" scope="application"/> <%= StaffOutputReportAction.getReportTitle(request) %></title>
    <link rel="stylesheet" href="../css/at.css" type="text/css">
    <script language="JavaScript" src="../js/at.js"></script>
    <script language="JavaScript" src="../js/calendar.js?r=1"></script>

<script language="JavaScript">
function checkFields(f)
{
    if(getVal(f.firstGrouping) == getVal(f.secondGrouping))
    {
        window.alert('Choose different grouping options');
        f.secondGrouping.focus();
        return false;
    }
    if(f.allUsers && f.allUsers[1].checked)
    {
        var b = false;
        for(i = 0; i < f.users.options.length; i++)
        {
            if(f.users.options[i].selected)
                b = true;
        }
        if(!b)
        {
            window.alert('Choose at least one person or select option "All Staff"');
            return false;
        }
    }
    if(fromDate > toDate)
    {
        window.alert('"From" date should be before "To" date');
        return false;
    }
    return true;
}
</script>
</head>
<body bgcolor="#ffffff" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0" onLoad="document.forms[0].autocomplete='off';">

<jsp:include page="../top.jsp" flush="false">
    <jsp:param name="pageSection" value="reports"/>
    <jsp:param name="pageAction" value="staffoutput"/>
</jsp:include>

<at:form action="/reports/staffoutput" method="post" onsubmit="return checkFields(this);">
<html:hidden property="pageAction" value=""/>
<html:hidden property="submitted" value="true"/>
<html:hidden property="singleUserMode"/>

<bean:define id="form" name="StaffOutputReportForm" type="com.actimind.actitime.reports.StaffOutputReportForm" />

<table width="770" align="center" cellspacing="0" cellpadding="4" border="0">
<tr>
<% int initialStep = 0; %>
<logic:equal name="form" property="singleUserMode" value="false">
    <% initialStep = 1; %>
    <td width="48"></td>
    <td></td>
</logic:equal>
    <td width="48"></td>
    <td></td>
    <td></td>
</tr>
<tr>
    <td colspan="<%=initialStep == 1 ? 5 : 3%>" class="pagetitle" valign="top"><%= StaffOutputReportAction.getReportTitle(request) %></td>
</tr>
<tr><td colspan="<%=initialStep == 1 ? 5 : 3%>"><at:errors/></td></tr>
<tr>
<logic:equal name="form" property="singleUserMode" value="false">
    <td width="48" nowrap class="formblocktitle">STEP 1.</td>
    <td class="formblocktitle">CHOOSE STAFF</td>
</logic:equal>
    <td width="48" nowrap class="formblocktitle">STEP <%=1+initialStep%>.</td>
    <td class="formblocktitle">CHOOSE REPORT FORMAT</td>
    <td></td>
</tr>
<tr>
<logic:equal name="form" property="singleUserMode" value="false">
    <td rowspan="12"></td>
    <td rowspan="12" valign="top">
        <table width="80%" cellspacing="0" cellpadding="2" border="0">
        <tr>
            <td class="text"><html:radio property="allUsers" value="true" onclick="setOptionsState(this.form.users, false);"/></td>
            <td class="text">All Staff</td>
        </tr>
        <tr>
            <td class="text"><html:radio property="allUsers" value="false"/></td>
            <td class="text">Selected Staff:</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>
                <at:select multiple="true" property="users" size="21" onchange="this.form.allUsers[1].checked = true" style="width: 180px" width="180" maxlength="27">
                    <at:options collection="usersList" property="id" labelProperty="formattedNameWithStatus"/>
                </at:select>
            </td>
        </tr>
        </table>
    </td>
</logic:equal>
    <td></td>
    <td colspan="2" style="padding-bottom: 12px">
        <table width="80%" cellspacing="0" cellpadding="2" border="0">
        <tr>
            <td width="5%" nowrap="1" align="right" class="text">First group results by:</td>
            <td width="95%" align="left">
                <html:select property="firstGrouping">
                    <html:option value='<%=""+StaffOutputReportForm.REPORT_GROUPING_BY_DATE%>'>Dates</html:option>
                    <html:option value='<%=""+StaffOutputReportForm.REPORT_GROUPING_BY_CUSTOMER%>'>Customers</html:option>
                    <html:option value='<%=""+StaffOutputReportForm.REPORT_GROUPING_BY_PROJECT%>'>Projects</html:option>
                    <logic:equal name="form" property="singleUserMode" value="false">
                    <html:option value='<%=""+StaffOutputReportForm.REPORT_GROUPING_BY_BILLING_TYPE%>'>Billing Types</html:option>
                    </logic:equal>
                </html:select>
            </td>
        <tr>
        </tr>
            <td align="right" class="text">then group by:</td>
            <td align="left">
                <html:select property="secondGrouping">
                    <html:option value='<%=""+StaffOutputReportForm.REPORT_GROUPING_NONE%>'>Nothing</html:option>
                    <html:option value='<%=""+StaffOutputReportForm.REPORT_GROUPING_BY_DATE%>'>Dates</html:option>
                    <html:option value='<%=""+StaffOutputReportForm.REPORT_GROUPING_BY_CUSTOMER%>'>Customers</html:option>
                    <html:option value='<%=""+StaffOutputReportForm.REPORT_GROUPING_BY_PROJECT%>'>Projects</html:option>
                    <logic:equal name="form" property="singleUserMode" value="false">
                    <html:option value='<%=""+StaffOutputReportForm.REPORT_GROUPING_BY_BILLING_TYPE%>'>Billing Types</html:option>
                    </logic:equal>                    
                </html:select>
            </td>
        </tr>
        </table>
    </td>
</tr>
<tr>
    <td colspan="3"><html:img src="/img/pixel.gif" width="1" height="10"/></td>
</tr>
<tr>
    <td nowrap class="formblocktitle">STEP <%=2+initialStep%>.</td>
    <td colspan="2"><span class="formblocktitle">SPECIFY DATE RANGE</span></td>
</tr>
<tr>
    <td></td>
    <td colspan="2" style="padding-bottom: 12px"><%@include file="date_utils.jsp"%></td>
</tr>
<tr>
    <td colspan="3"><html:img src="/img/pixel.gif" width="1" height="10"/></td>
</tr>
<tr>
    <td nowrap class="formblocktitle">STEP <%=3+initialStep%>.</td>
    <td nowrap width="30%" class="formblocktitle">CHOOSE CUSTOMERS TO SHOW</td>
    <td <%if (initialStep == 1) {%> width="30%" <%}%>>
        <at:select property="customer" childSelect="project" firstChildText="-- All projects --" firstChildValue="0" style="width: 190px" width="190" maxlength="31">
            <at:option value="0">-- All customers --</at:option>
            <at:options collection="<%=Keys.CUSTOMERS_LIST_KEY%>" property="id" labelProperty="name"/>
        </at:select>
    </td>
</tr>
<tr>
    <td colspan="3"><html:img src="/img/pixel.gif" width="1" height="10"/></td>
</tr>
<tr>
    <td nowrap class="formblocktitle">STEP <%=4+initialStep%>.</td>
    <td nowrap class="formblocktitle">CHOOSE PROJECTS TO SHOW</td>
    <td>
        <at:select property="project" parentSelect="customer" firstChildText="-- All projects --" firstChildValue="0" style="width: 190px" width="190" maxlength="31">
            <at:options collection="<%=Keys.PROJECTS_LIST_KEY%>" property="id" parentProperty="customerId" labelProperty="name"/>
        </at:select>
    </td>
</tr>
<tr>
    <td colspan="3"><html:img src="/img/pixel.gif" width="1" height="10"/></td>
</tr>
<tr>
    <td nowrap class="formblocktitle">STEP <%=5+initialStep%>.</td>
    <td colspan="2"><span class="formblocktitle">CHOOSE LEVEL OF DETAILS</span></td>
</tr>
<tr>
    <td></td>
    <td colspan="2" class="text"><html:radio property="showTasks" value="true"/>Show tasks</td>
</tr>
<tr>
    <td></td>
    <td colspan="2" class="text"><html:radio property="showTasks" value="false"/>Hide tasks</td>
</tr>
<tr>
    <td colspan="<%=initialStep==1?5:3%>"><html:img src="/img/pixel.gif" width="1" height="10"/></td>
</tr>
<tr>
    <td nowrap="1" bgcolor="#E5E5E5" class="formblocktitle">STEP <%=6+initialStep%>.</td>
    <td class="text" align="center" bgcolor="#E5E5E5" colspan="<%=initialStep==1?4:2%>">
        <table cellspacing="0" cellpadding="2" border="0" width="100%">
        <tr>
            <td width="40%" align="right"><input type="submit" onclick="this.form.pageAction.value='html'; return true;" value="Generate HTML Report"></td>
            <td class="text" align="center">-- OR --</td>
            <td width="50%" align="left"><input type="submit" onclick="this.form.action='<html:rewrite href='staffoutput.csv'/>'; this.form.pageAction.value='csv'; return true;" value="Generate CSV Report"></td>
        </tr>
        </table>
    </td>
</tr>
</table>

</at:form>
</body>
</html>
